<?php
/**
  * @version 0.4
  * @author Cor Bosman (roundcube@wa.ter.net)
  */

class help_ui extends rcube_plugin
{
  public function init() {
    // $this->add_hook('render_page', array($this, 'help_start')); 
    $this->add_hook('template_container', array($this, 'help_start'));
    $this->register_action('plugin.help_ui_get_elements', array($this, 'get_elements'));
  }
  
  function get_elements() {
    $this->load_config();
    $rcmail = rcmail::get_instance();
    $this->add_texts('localization', true);
    
    $help_ui_elements = $rcmail->config->get('help_ui_elements', array());                             
    $rcmail->output->command('plugin.help_ui_receive', array('elements' => $help_ui_elements)); 
  }
  
  function help_start($p) { 
    if ($p['name'] == "listcontrols") {
      $rcmail = rcmail::get_instance();
      $this->add_texts('localization', true);
       
      $skin  = $rcmail->config->get('skin');
      if(!file_exists('plugins/help_ui/skins/' . $skin . '/images/monitor.png')) {
        $skin = 'default';
      }
      
      $this->include_script('js/help_ui.js');
      $this->include_script('js/jquery.tools.min.js');
      $this->include_stylesheet("help_ui.css");
      
      $div     = html::tag('div', array('class' => 'help_ui_overlay_clone'));
      $helpdiv = html::tag('span', array('id' => 'help_ui_link_title'), $this->gettext('title') . ':&nbsp;') . html::a(array('id' => 'help_ui_link', 'href' => '#', 'class' => 'button', 'title' => $this->gettext('title')), html::img(array('src' => "plugins/help_ui/skins/$skin/images/monitor.png")));
      $rcmail->output->add_footer($div);
      $p['content'] .= $helpdiv;
    }
    return($p);
  }
}
?>